<?php
// 20090211
// first implementation


if ($_POST) {
	$uploaddir = "users/$name/photos/";
	$time = time();
//$uploadorig = basename($_FILES['photo']['name']);
	$uploadfile = $uploaddir . $time;


	if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile)) {
		$imginfo = getimagesize ($uploadfile);
		
		if ($imginfo) {
			$width 	= $imginfo[0];
			$height = $imginfo[1]; 
			$title 	= escapestr($_POST['title']); 
			$access 	= escapestr($_POST['access']); 
			$type 	= escapestr($_POST['type']); 

			$query 	= "INSERT into `photos` (`owner`,`access`,`type`,`time`,`title`,`width`,`height`) values ('$id','$access','$type','$time','$title','$width','$height')";
			$result = mysql_query ($query);
			if ($result) {
    		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_photoupload"), GetLangString($lang,"msg_photouploaded") ."<br>"
			.bb2html("[photo=".mysql_insert_id()."]"));
			
			
    	} else {
    		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"), GetLangString($lang,"msg_dberror")."<br>$query");
    		unlink($uploadfile);
    	}
    } else {
    	unlink($uploadfile);
    	$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"), GetLangString($lang,"msg_badphoto"));
    }
	} else {
    $SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_photoupload"), GetLangString($lang,"msg_uploaderr"));
	}
}

$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_photoupload"), GetLangString($lang,"msg_photoupload")." 
<form enctype=\"multipart/form-data\" action=\"index.php?do=photoupload\" method=\"POST\">
    <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"8000000\" />".
    FormatSmallElement(GetLangString($lang,"txt_phototitle"),"
    <input type=\"text\" name=\"title\"/>").
		FormatSmallElement(GetLangString($lang,"txt_phototype"),"
		<select name=\"type\" size=\"1\">
		<option value=\"0\" selected>".GetLangString($lang,"txt_na")."</option>
		<option value=\"1\" 				>".GetLangString($lang,"txt_photo_you")."</option>
		<option value=\"2\"				 	>".GetLangString($lang,"txt_photo_people_you")."</option>
		<option value=\"3\" 				>".GetLangString($lang,"txt_photo_people_other")."</option>		
		<option value=\"4\" 				>".GetLangString($lang,"txt_photo_no-people")."</option>		
		<option value=\"5\" 				>".GetLangString($lang,"txt_art_drawing")."</option>		
		<option value=\"6\" 				>".GetLangString($lang,"txt_art_painting")."</option>		
		<option value=\"7\" 				>".GetLangString($lang,"txt_art_other")."</option>		
		<option value=\"8\" 				>".GetLangString($lang,"txt_art_digital_pixel")."</option>		
		<option value=\"9\" 				>".GetLangString($lang,"txt_art_digital_vector")."</option>		
		<option value=\"10\"				>".GetLangString($lang,"txt_art_digital_other")."</option>		
		</select>").		
		FormatSmallElement(GetLangString($lang,"txt_photoaccess"),"
		<select name=\"access\" size=\"1\">
		<option value=\"0\" selected>".GetLangString($lang,"txt_public")."</option>
		<option value=\"1\"					>".GetLangString($lang,"txt_friends")."</option>
		<option value=\"2\"					>".GetLangString($lang,"txt_private")."</option>		
		</select>").		
		FormatSmallElement(GetLangString($lang,"txt_photofile"),"
    <input name=\"photo\" type=\"file\">")."
    <input type=\"submit\" value=\"".GetLangString($lang,"txt_photoupload")."\" />
</form>
");
?>
